<template>
  <div class>
    <h2>库存统计图</h2>
    <div id="chart4" class="chart"></div>
  </div>
</template>

<script>
import { inject, onMounted, reactive } from "vue";
export default {
  name: "ItemFour",
  setup() {
    let $echarts = inject("echarts");
    let $axios = inject("axios");
    let data = reactive({});

    async function getData() {
      data = await $axios.get(`/four/data`);
    }

    onMounted(() => {
      let myEchart = $echarts.init(document.getElementById("chart4"));
      getData().then(() => {
        console.log(data);

        myEchart.setOption({
          grid: {
            left: "3%",
            right: "4%",
            bottom: "12%",
            containLabel: true
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          legend: {
            textStyle: {
              color: "#fff",
              fontSize: 12
            }
          },
          xAxis: {
            type: "category",
            data: data.data.data.chartData.day,
            axisLine: {
              lineStyle: {
                color: "#fff"
              }
            }
          },
          yAxis: {
            type: "value",
            axisLine: {
              lineStyle: {
                color: "#fff"
              }
            }
          },
          series: [
            {
              name: "服饰",
              data: data.data.data.chartData.num.Clothes,
              type: "bar",
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "数码",
              data: data.data.data.chartData.num.digit,
              type: "bar",
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "家电",
              data: data.data.data.chartData.num.Electrical,
              type: "bar",
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "家居",
              data: data.data.data.chartData.num.gear,
              type: "bar",
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "日化",
              data: data.data.data.chartData.num.Chemicals,
              type: "bar",
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            }
          ]
        });
      });
    });

    return { getData, data };
  }
};
</script>

<style scoped lang="less">
h2 {
  height: 0.6rem;
  line-height: 0.6rem;
  color: #fff;
  font-size: 0.25rem;
  text-align: center;
}
.chart {
  height: 4.5rem;
}
</style>
